package effect
{
	import effect.image.Reflect;
	import effect.image.RollPhoto;
	import effect.image.tool.Contain;
	
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	[SWF(backgroundColor="#000000", width="1280", height="600")]
	public class InvertedImage extends MovieClip
	{
		private var array:Array= new Array();//用于管理的数组
		private var list:MovieClip=new MovieClip();//图片容器
		private var myphoto:RollPhoto;//图片滚动对象
		private var count:int=0;//图片加载的计数器
		private var imageList:Array=new Array();
		public function InvertedImage()
		{
			init();
		}
		private function init():void
		{
			myphoto=new RollPhoto(stage);//初始化对象
			myphoto.setPorperty(1.4,0.0025,8);//设置属性
			addEventListener(Event.ENTER_FRAME,Run);
			addImages("./image/1.png","./image/2.png","./image/3.png","./image/4.png","./image/5.png","./image/6.png","./image/7.png");//外部加载图片
			addChild(list);
			list.y=60;
			list.x=20;
			
		}
		//创建列表物体
		private function createObj(images:Array):void
		{
			
			for (var i:uint=0; i<images.length; i++)
			{
				var bit:MovieClip=new MovieClip();//空白影片剪辑				
				bit.addChild(images[i]);
				bit.buttonMode=true;
				bit.x=i*(bit.width+8);
				bit.y=150;
				var r1:Reflect = new Reflect({mc:bit, alpha:30, ratio:60, distance:0, updateTime:-1, reflectionDropoff:0});
				array.push(bit);//数组管理
				list.addChild(bit);//容器管理
				Contain.RegPoint(bit,new Point(50,140));//重新更改注册点
				bit.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
			}
			stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
		}
		
		private function Run(event:Event):void
		{
			trace(String(System.totalMemory/1024)+"/kb");//内存监控
		}
		private function mouseMoveHandler(e:MouseEvent):void
		{
			if (list.hitTestPoint(mouseX,mouseY) && mouseY<300)
			{
				myphoto.ZoomX(array);//以x轴为例
			}
			else
			{
				System.gc();
				myphoto.Rest(array,"x");//复位
			}
		}
		
		private function mouseDownHandler(event:MouseEvent):void
		{
			trace(event.currentTarget);
		}
		//加载外部图片
		private function addImages(...args):void
		{
			count=args.length;
			for(var i:int=0;i<args.length;i++)
			{
				var loader:Loader=new Loader();
				loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
				loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onError);
				loader.load(new URLRequest(args[i]));
			}
		}
		private function onComplete(event:Event):void
		{
			var bitmap:Bitmap=event.currentTarget.content as Bitmap;
			imageList.push(bitmap);
			event.currentTarget.removeEventListener(Event.COMPLETE,onComplete);
			count--;
			if(count==0)
			{ 
				trace(imageList.length);
				createObj(imageList);
			}
			
			
		}
		private function onError(event:Event):void
		{
			throw new Error("路径错误");
		}
		
	}
}